package com.wf.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.wf.entity.User;
import com.wf.entity.Userinfo;
import com.wf.provider.UserProvider;
import com.wf.provider.UserinfoProvider;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;

/**
 * Created by yuzhongbo on 2017/5/3.
 */
@RestController
@RequestMapping(value="/userinfo")
public class UserinfoController  {
    private final Logger logger=Logger.getLogger(UserinfoController.class);

    public static final String DEFAULT_ERROR_VIEW = "backerror";
    @Autowired
    private UserinfoProvider userinfoProvider;
    @Autowired
    private UserProvider userProvider;

   //@HystrixCommand(fallbackMethod="getUserListBack")
    @RequestMapping(value = "/getUserList/{name}", method = RequestMethod.GET)
    public ModelAndView getUserList(@PathVariable(value = "name") String name) {
        logger.info("===call getUserListC===");
        ModelAndView mv=new ModelAndView();
        List<Userinfo> userinfos=userinfoProvider.getUserList(name);
        mv.addObject("userinfos",userinfos);
        mv.setViewName("userlist");
        return mv;
    }

    public ModelAndView getUserListBack(String name){
        ModelAndView mv=new ModelAndView();
        mv.addObject("message", "获取用户"+name+"失败");
        mv.setViewName(DEFAULT_ERROR_VIEW);
        return mv;
    }

}
